﻿//新增用户表
InsertSys_User = function() {
    var InsertSys_UserForm = Ext.create("Ext.form.Panel", {
        width: 360, 
       
        layout: "anchor",
        defaultType: "textfield",
        labelWidth: 55,
        baseCls: "x-plain",
        defaults: { labelAlign: 'right', anchor: '90%', msgTarget: "side" },
        buttonAlign: "center",
        bodyStyle: "padding:0 0 0 0",
        items: [
        {
            xtype:'tabpanel',
            plain:true,
            activeTab: 0,
            height:400,
            
            items:[{
                title:'基本信息',
               defaults:{bodyStyle:'padding:10px',labelAlign: 'right', anchor: '90%', msgTarget: "side"},
                defaultType: 'textfield',

                items: [ 
                   {
                        name: "UserID",
                        fieldLabel: "<font color='red'>*</font>ID",
                        allowBlank: false,
                        blankText: "用户ID号不能为空",
                        xtype: "hiddenfield",
                        regex: /^[\d]{0,10}$/,
                        xtype: "hiddenfield",
                        regexText: "请填写0～10个数字"
                    }, {
                        name: "U_LoginName",
                        fieldLabel: "<font color='red'>*</font>登陆名",
                        allowBlank: false,
                        blankText: "登陆名不能为空",
                        regex: /^[\da-zA-Z]{1,20}$/,
                        regexText: "请填写1～20个数字或字母"
                    }, {
                        name: "U_Password",
                        fieldLabel: "<font color='red'>*</font>密码",
                        allowBlank: false,
                        blankText: "密码不能为空",
                        inputType : 'password',
                        regex: /^[\da-zA-Z]{1,9}$/,
                        regexText: "请填写1～9个数字或字母"
                    }, {
                        name: "U_CName",
                        fieldLabel: "中文姓名",
                        regex: /^[\da-zA-Z]{0,20}$/,
                        regexText: "请填写0～20个数字或字母"
                    }, {
                        name: "U_EName",
                        fieldLabel: "英文名",
                        regex: /^[\da-zA-Z]{0,9}$/,
                        regexText: "请填写0～9个数字或字母"
                    }, {
                        name: "U_GroupID",
                        fieldLabel: "<font color='red'>*</font>所属部门",
                        allowBlank: false,
                        blankText: "所属部门不能为空",
                        regex: /^[\d]{0,10}$/,
                        regexText: "请填写0～10个数字"
                    }, {
                        name: "U_Email",
                        fieldLabel: "电子邮件",
                        regex: /^[\da-zA-Z]{0,9}$/,
                        regexText: "请填写0～9个数字或字母"
                    }, {
                        name: "U_Type",
                        fieldLabel: "用户类型",
                        xtype: "combo",
                        //传入后台真实值value field /value
                        editable: false,
                        anchor: '90%',
                        value: 1,
                        store: Ext.create('Ext.data.Store', {
                            fields: ['show', 'value'],
                            data: [
			                    { "show": "管理用户", "value":0 },
			                    { "show": "普通用户", "value":1 }
			                ]
                        }),
                        queryMode: 'local',
                        displayField: 'show',
                        valueField: 'value'
                    }, {
                        name: "U_Status",
                        fieldLabel: "当前状态",
                        xtype: "combo",
                        //传入后台真实值value field /value
                        xtype: 'combo',
                        editable: false,
                        anchor: '90%',
                        value: 0,
                        store: Ext.create('Ext.data.Store', {
                            fields: ['show', 'value'],
                            data: [
			                    { "show": "禁止登陆", "value": 0 },
			                    { "show": "正常", "value": 1 },
			                    { "show": "删除", "value":2 }
			                ]
                        }),
                        queryMode: 'local',
                        displayField: 'show',
                        valueField: 'value'
                    }, {
                        name: "U_Sex",
                        fieldLabel: "性别",
                        xtype: "combo",
                        //传入后台真实值value field /value
                        xtype: 'combo',
                        editable: false,
                        anchor: '90%',
                        value: 0,
                        store: Ext.create('Ext.data.Store', {
                            fields: ['show', 'value'],
                            data: [
			                    { "show": "男", "value": 1 },
			                    { "show": "女", "value":0 }
			                ]
                        }),
                        queryMode: 'local',
                        displayField: 'show',
                        valueField: 'value'
                    }, {
                        xtype:"datefield",
                        name: "U_BirthDay",
                        fieldLabel: "出生日期",
                    }, {
                        name: "U_MobileNo",
                        fieldLabel: "手机号",
                        regex: /^[\da-zA-Z]{0,9}$/,
                        regexText: "请填写0～9个数字或字母"
                    }]
                    
                    
                    
            },{
                title:'其他信息',
                defaults:{bodyStyle:'padding:10px',labelAlign: 'right', anchor: '90%', msgTarget: "side"},
                defaultType: 'textfield',

                items: [
                     {
                            name: "U_Licence",
                            fieldLabel: "用户序列号",
                            regex: /^[\da-zA-Z]{0,9}$/,
                            regexText: "请填写0～9个数字或字母"
                        }, {
                            name: "U_Remark",
                            fieldLabel: "备注说明",
                            regex: /^[\da-zA-Z]{0,200}$/,
                            regexText: "请填写0～200个数字或字母"
                        }, {
                            name: "U_IDCard",
                            fieldLabel: "身份证号码",
                            regex: /^[\da-zA-Z]{0,9}$/,
                            regexText: "请填写0～9个数字或字母"
                        },{
                            name: "U_UserNO",
                            fieldLabel: "员工编号",
                            regex: /^[\da-zA-Z]{0,9}$/,
                            regexText: "请填写0～9个数字或字母"
                        }, {
                            xtype:"datefield",
                            name: "U_WorkStartDate",
                            fieldLabel: "到职日期",
                        },{
                        name: "U_Mac",
                        fieldLabel: "锁定机器硬件地址",
                        regex: /^[\da-zA-Z]{0,9}$/,
                        regexText: "请填写0～9个数字或字母"
                        },
                        {
                            xtype:"datefield",
                            name: "U_WorkEndDate",
                            fieldLabel: "离职日期",
                        }, {
                            name: "U_CompanyMail",
                            fieldLabel: "公司邮件地址",
                            regex: /^[\da-zA-Z]{0,9}$/,
                            regexText: "请填写0～9个数字或字母"
                        }, {
                            name: "U_Title",
                            fieldLabel: "职称",
                            regex: /^[\d]{1,10}$/,
                            regexText: "请填写1～10个数字"
                        }, {
                            name: "U_Extension",
                            fieldLabel: "分机号",
                            regex: /^[\da-zA-Z]{0,9}$/,
                            regexText: "请填写0～9个数字或字母"
                        }, {
                            name: "U_HomeTel",
                            fieldLabel: "家中电话",
                            regex: /^[\da-zA-Z]{0,9}$/,
                            regexText: "请填写0～9个数字或字母"
                        }, {
                            name: "U_PhotoUrl",
                            fieldLabel: "用户照片网址",
                            regex: /^[\da-zA-Z]{0,255}$/,
                            regexText: "请填写0～255个数字或字母"
                        }, {
                            name: "U_ExtendField",
                            fieldLabel: "扩展字段",
                            regex: /^[\w]{0,10000}$/,
                            regexText: "请填写0～10000个数字或字母"
                        }, {
                            xtype:"datefield",
                            name: "U_DateTime",
                            fieldLabel: "操作时间"
                        }, {
                            name: "U_LastIP",
                            fieldLabel: "最后访问IP",
                            regex: /^[\da-zA-Z]{0,9}$/,
                            regexText: "请填写0～9个数字或字母"
                        }, {
                            xtype:"datefield",
                            name: "U_LastDateTime",
                            fieldLabel: "最后访问时间"
                        }
                         
                         ]
         }]
            
            }
        ]
    });


    var InsertSys_UserWin = Ext.create('Ext.window.Window', {
        title: "新增用户",
        width: 400,
        height: 480,
       
        autoScroll:true,
        layout: "fit",
        //不可以随意改变大小
        resizable: false,
        //是否可以拖动
        //draggable:false,
        defaultType: "textfield",
        collapsible: true, //允许缩放条
        closeAction: 'destroy',
        closable: true,
        //弹出模态窗体
        modal: 'true',
        buttonAlign: "center",
        bodyStyle: "padding:10px 0 0 15px",
        items: [InsertSys_UserForm],

        buttons: [{
            text: "保存信息",
            minWidth: 70,
            handler: function() {
                //alert(InsertSys_UserForm.getForm().isValid())
                if (InsertSys_UserForm.getForm().isValid()) {
                    //弹出效果 Ext.MessageBox.alert("asdf");
                    Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                    setTimeout(function() { }, 1000);
                    InsertSys_UserForm.form.submit({
                        url: "/Manager/Sys_User/Insert/",
                        method: "POST",
                        success: function(form, action) {
                            //成功后
                            Ext.MessageBox.hide();
                            var flag = action.result.success;
                            if (flag == "true") {
                                Sys_UserStore.loadPage(1);
                                Ext.helper.msg("恭喜", "新增成功!");
                                InsertSys_UserWin.hide();
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.MessageBox.alert("新增失败!", message);
                                }
                                else {
                                    Ext.MessageBox.alert("提示!", "新增失败!");
                                    InsertSys_UserWin.hide();
                                }

                            }
                        },
                        failure: function(form, action) {
                            Ext.MessageBox.alert("提示!", "新增失败!");
                        }
                    });
                }
            }
        }, {
            text: "重置",
            minWidth: 70,
            qtip: "重置数据",
            handler: function() {
                //加载表单数据
                InsertSys_UserForm.getForm().reset();
            }
        }, {
            text: "取 消",
            minWidth: 70,
            handler: function() {
                InsertSys_UserWin.hide();
            }
}]

        });

        InsertSys_UserWin.show();
    }
